/*
 * @Author: 胡海
 * @Date: 2019-11-13 21:55:39
 * @LastEditors: 胡海
 * @LastEditTime: 2020-04-07 21:19:14
 * @Description: 
 */
const Koa = require('koa')
const InitManager = require('./core/init')
const cors = require('koa2-cors')
const koaBody = require('koa-body')
const static = require('koa-static')
const path = require('path')
const catchError = require('./middlewares/exception')


const ENV = 'dev-phblt'

const app = new Koa()

// 跨域
// app.use(cors({
//     origin: ['http://localhost:9528'],
//     credentials: true
// }))
// 静态资源
app.use(static(path.join(__dirname,'./static')))
app.use(catchError)
// 接收post参数解析
app.use(koaBody({
    multipart: true,
}))

app.use(async (ctx, next) => {
    ctx.state.env = ENV
    await next()
})

InitManager.initCore(app)

app.listen(3000, () => {
    console.log('服务开启在3000端口')
})

// MVC